package com.share.example.javafx.service.impl;

/**
 * @author 01401061 - 孙艳强
 * @date 2020/12/3 18:45
 */

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.example.javafx.mapper.DictionaryMapper;
import com.share.example.javafx.model.Dictionary;
import com.share.example.javafx.service.IDictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary> implements IDictionaryService {
    private Map<String, Dictionary> dictMap = new HashMap<>();

    @Resource
    private DictionaryMapper dictionaryMapper;

    @Override
    public Object init() {
        List<Dictionary> list = dictionaryMapper.listByKey(null);
        Map<String, Dictionary> tmpMap = new HashMap<>();
        for (Dictionary record : list) {
            tmpMap.put(record.getCode(), record);
        }
        return dictMap = tmpMap;
    }

    @Override
    public Dictionary getByCode(String code) {
        return dictMap.get(code);
    }

    @Override
    public List<Dictionary> listByKey(String code) {
        return dictionaryMapper.listByKey(code);
    }
}
